package com.ruoyi.web.controller.plan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.plan.domain.StudyContent;
import com.ruoyi.plan.service.IStudyContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author MLYNDHG
 * @version 1.0
 * @description 学习内容Controller
 * @date 2023/12/6 15:07
 */
@RestController
@RequestMapping("/plan/content")
public class StudyContentController extends BaseController
{
 @Autowired
 private IStudyContentService studyContentService;

 /**
  * 查询学习内容列表
  */
 @PreAuthorize("@ss.hasPermi('plan:content:list')")
 @GetMapping("/list")
 public TableDataInfo list(StudyContent studyContent)
 {
  startPage();
  List<StudyContent> list = studyContentService.selectStudyContentList(studyContent);
  return getDataTable(list);
 }

 /**
  * 导出学习内容列表
  */
 @PreAuthorize("@ss.hasPermi('plan:content:export')")
 @Log(title = "学习内容", businessType = BusinessType.EXPORT)
 @PostMapping("/export")
 public void export(HttpServletResponse response, StudyContent studyContent)
 {
  List<StudyContent> list = studyContentService.selectStudyContentList(studyContent);
  ExcelUtil<StudyContent> util = new ExcelUtil<StudyContent>(StudyContent.class);
  util.exportExcel(response, list, "学习内容数据");
 }

 /**
  * 获取学习内容详细信息
  */
 @PreAuthorize("@ss.hasPermi('plan:content:query')")
 @GetMapping(value = "/{id}")
 public AjaxResult getInfo(@PathVariable("id") Long id)
 {
  return success(studyContentService.selectStudyContentById(id));
 }

 /**
  * 新增学习内容
  */
 @PreAuthorize("@ss.hasPermi('plan:content:add')")
 @Log(title = "学习内容", businessType = BusinessType.INSERT)
 @PostMapping
 public AjaxResult add(@RequestBody StudyContent studyContent)
 {
  return toAjax(studyContentService.insertStudyContent(studyContent));
 }

 /**
  * 修改学习内容
  */
 @PreAuthorize("@ss.hasPermi('plan:content:edit')")
 @Log(title = "学习内容", businessType = BusinessType.UPDATE)
 @PutMapping
 public AjaxResult edit(@RequestBody StudyContent studyContent)
 {
  return toAjax(studyContentService.updateStudyContent(studyContent));
 }

 /**
  * 删除学习内容
  */
 @PreAuthorize("@ss.hasPermi('plan:content:remove')")
 @Log(title = "学习内容", businessType = BusinessType.DELETE)
 @DeleteMapping("/{ids}")
 public AjaxResult remove(@PathVariable Long[] ids)
 {
  return toAjax(studyContentService.deleteStudyContentByIds(ids));
 }
}